package com.doit.mr.day04.json;

import com.doit.mr.day03.User;
import com.google.gson.Gson;

/**
 * @DATE 2021/12/8/21:28
 * @Author MDK
 * @Version 2021.2.2
 **/
public class TestJson {
    public static void main(String[] args) {
        //javabean--->json串
        User user = new User(1,"zss",23);
        //JSON解析工具
        Gson gson = new Gson();
        String str = gson.toJson(user);
        System.out.println(str);        //{"id":1,"name":"zss","age":23}

        //将JSON串转化成java对象
        User user1 = gson.fromJson(str, User.class);
        System.out.println(user1);      //User{id=1, name='zss', age=23}
    }
}
